package com.liao.controller;

import com.liao.bean.*;
import com.liao.service.ModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/wfx")
public class WfxController {

    @Autowired
    private ModuleService moduleService;

    @ResponseBody
    @RequestMapping("/init")
    public WfxInit  init(HttpSession session) throws Exception {
        WfxInit wfxInit = new WfxInit();
        wfxInit.setHomeInfo(new HomeInfo());
        wfxInit.setLogoInfo(new LogoInfo());
        //根据账户有层级地查询所有菜单
        User existUser = (User) session.getAttribute("existUser");
        if(null != existUser){
            List<Module> moduleList = moduleService.queryModuleListHierarchyByAccount(existUser.getAccount());
            wfxInit.setMenuInfo(moduleList);
        }
//        List<Module> moduleList = moduleService.queryModuleListHierarchyByAccount("admin");
//        wfxInit.setMenuInfo(moduleList);
        return wfxInit;
    }
}
